# 等式：WWWDOT - GOOGLE = DOTCOM
# 每个字符代表一个数，不能0开头，不同字母对应的数字不重复，找出数字字母对应关系，使等式成立

# 穷举法
# 内层列表的三个值分别为：题目的字母，初始值，是否是开头数字
word_list = [['W', -1, True], ['D', -1, True], ['O', -1, False], ['T', -1, False], ['G', -1, True],
            ['L', -1, False], ['E', -1, False], ['C', -1, False], ['M', -1, False]]
num_list = []
for i in range(10):
    # 把数字0-9加入列表，并附带状态False，表示未使用过
    num_list.append([i, False])

# for num in num_list:
#     for word in word_list:
#         if (num[1] is False) and (word[2] is True) and (num[0] != 0):
def get_value(word):
    for num in num_list:
        if num[1] is False and word[2] == False:
            num[1] = True
            return num[0]
        elif (num[1] is False) and (word[2] == True) and (num[0] != 0) :
            num[1] = True
            return num[0]


for word in word_list:
    word[1] = get_value(word)
print(word_list)





